<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="年龄" prop="year">
        <el-input v-model="queryParams.year" placeholder="请输入年龄" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:encounterUser:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:encounterUser:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:encounterUser:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:encounterUser:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="encounterUserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="组织id" align="center" prop="organizeId" /> -->
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="用户头像" align="center" prop="userAvatar">
        <template slot-scope="scope">
          <image-preview :src="scope.row.userAvatar" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="用户手机号" align="center" prop="userPhone" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="year" />
      <el-table-column label="活跃时长" align="center" prop="time" />
      <el-table-column label="最近登录时间" align="center" prop="loginTime" />
      <el-table-column label="注册时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属组织" align="center" prop="orgName" />
      <el-table-column label="用户权限管理" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.isAdmin" :active-value="1" :inactive-value="0" active-text="发布动态"
            inactive-text="" />
          <el-switch v-model="scope.row.isAdmin" :active-value="1" :inactive-value="0" active-text="聊天"
            inactive-text="" />
          <el-switch v-model="scope.row.isAdmin" :active-value="1" :inactive-value="0" active-text="评论"
            inactive-text="" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="身份证号" align="center" prop="cardNumber" />
      <el-table-column label="实名认证 1-未认证 2-已认证" align="center" prop="idCert" />
      <el-table-column label="工作认证 1-未认证 2-已认证" align="center" prop="jobCert" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['system:encounterUser:edit']">个人信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 查看用户信息扩展（遇见黄石）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="组织名称" prop="orgName">
          <span>{{ form.orgName }}</span>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <span>{{ form.userId }}</span>
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <span>{{ form.nickName }}</span>
        </el-form-item>
        <el-form-item label="身高" prop="height">
          <span>{{ form.height }}</span>
        </el-form-item>
        <el-form-item label="体重" prop="weight">
          <span>{{ form.weight }}</span>
        </el-form-item>
        <el-form-item label="学历" prop="edu">
          <span>{{ form.edu }}</span>
        </el-form-item>
        <el-form-item label="头像" prop="userAvatar">
          <image-preview :src="form.userAvatar" :width="50" :height="50" />
        </el-form-item>
        <el-form-item label="近照" prop="recentPhoto">
          <image-preview :src="form.recentPhoto" :width="50" :height="50" />
        </el-form-item>
        <el-form-item label="姓名" prop="realName">
          <span>{{ form.realName }}</span>
        </el-form-item>
        <el-form-item label="年龄" prop="year">
          <span>{{ form.year }}</span>
        </el-form-item>
        <el-form-item label="身份证号" prop="cardNumber">
          <span>{{ form.cardNumber }}</span>
        </el-form-item>
        <el-form-item label="个性标签" v-if="form.tagObj && form.tagObj.length > 0" prop="tagObj">
          <el-tag v-for="item in form.tagObj" :key="item.id" type="success" size="mini">{{ item.tagName }}</el-tag>
        </el-form-item>
        <el-form-item label="实名认证" prop="idCert">
          <span>{{ form.idCert == 1 ? '未认证' : '已认证' }}</span>
        </el-form-item>
        <el-form-item label="工作认证" prop="jobCert">
          <!-- <span>{{ form.jobCert == 1 ? '未认证' : '已认证' }}</span> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEncounterUser, getInfo, delEncounterUser, addEncounterUser, updateEncounterUser } from "@/api/system/encounterUser";
import { parseTime } from "@/utils/ruoyi";

export default {
  name: "EncounterUser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息扩展（遇见黄石）表格数据
      encounterUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 999,
        organizeId: null,
        userId: null,
        nickName: null,
        height: null,
        weight: null,
        edu: null,
        userAvatar: null,
        recentPhoto: null,
        realName: null,
        sex: null,
        year: null,
        cardNumber: null,
        idCert: null,
        jobCert: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户信息扩展（遇见黄石）列表 */
    getList() {
      this.loading = true;
      listEncounterUser(this.queryParams).then(response => {
        this.encounterUserList = response.data;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        organizeId: null,
        userId: null,
        nickName: null,
        height: null,
        weight: null,
        edu: null,
        userAvatar: null,
        recentPhoto: null,
        realName: null,
        sex: null,
        year: null,
        cardNumber: null,
        idCert: null,
        jobCert: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息扩展（遇见黄石）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户信息扩展（遇见黄石）";
      });
    },
    /** 查看按钮操作 */
    handleView(row) {
      const id = row.userId
      getInfo({
        userId: id
      }).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看用户信息（遇见黄石）";
      });
      
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEncounterUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEncounterUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户信息扩展（遇见黄石）编号为"' + ids + '"的数据项？').then(function () {
        return delEncounterUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/encounter/user/adminUserExcel', {
        ...this.queryParams
      }, `encounterUser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
